<?php
class CategoryController extends Controller{
	private $db;
	public function __init(){
		$this->db=new CategoryModel;
	}
	public function index(){
		$data=$this->db->getAll();
		$this->assign('data',$data);
		$this->display('index.html');
	}
	//添加博客
	public function add(){
		if(IS_POST){
			if($this->db->addCate($_POST)){
				$this->success('添加栏目成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display('add.html');
		}
	}
	//编辑栏目

	public function edit(){
		if(IS_POST){
			if($this->db->editCate($_POST)){
				$this->success('栏目名称编辑成功过',__CONTROLLER__);
			}else{
				$this->error('栏目名称编辑失败');
			}
		}else{
			$field=$this->db->where("cid={$_GET['cid']}")->find();
			$this->assign('field',$field);
			$this->display('edit.html');
		}
		
	}
	//删除栏目
	public function del(){
		if($this->db->delCate()){
			$this->success('删除栏目成功',__CONTROLLER__);
		}else{
			$this->error('删除栏目失败');
		}
	}
}
?>